package com.ck.hxc.utils.deepseek;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import java.io.IOException;
import java.net.http.HttpResponse;
import java.util.Scanner;

/**
 * @author hxc
 * @since 2025/2/19 10:28
 */
public class DeepSeekChatLA {

    private static final String API_URL = "https://api.deepseek.io/chat"; //api密钥
    private static final String CHAT_URL = "https://api.deepseek.io/chat";

    /*public static void main(String[] args) throws IOException, InterruptedException {
        Scanner scanner = new Scanner(System.in);
        JSONArray messages = new JSONArray();
        
        while (true) {
            //显示菜单
            System.out.println("请输入 1提问  2退出");
            String choice = scanner.nextLine();
            
            if (choice.equals("1")) {
                System.out.println("输入您的问题");
                String userQuestion = scanner.nextLine();

                //用户消息添加到消息组
                JSONObject userMessage = new JSONObject();
                userMessage.put("role", "user");
                userMessage.put("content", userQuestion);
                messages.add(userMessage);

                //获取助手回应
                JSONObject assistantResponse = sendMessage(messages);
                messages.add(assistantResponse);

                //输出对话内容
                System.out.println("用户："+ userQuestion);
                System.out.println("助手：" + assistantResponse.getString("content"));
            }else if (choice.equals("2")) {
                //推出程序
                System.out.println("退出对话程序");
                break;
            }else {

            }
        }
        
    }*/

    //发送消息并获取助手的响应
    /*private static JSONObject sendMessage(JSONArray messages) throws Exception {
        String url = BASE_URL + "/chat/completions".//请求 URL
        //创建请求的 JSON 数据
        JSONObject payload =new JSONObject();
        payload.put("model","deepseek-chat");
        payload.put("messages",messages);
        //初始化 Httpclient 和 HttpPost
        Httpclient client = HttpClients.createDefault();
        HttpPost postMethod = new HttpPost(url);
        // 设置请求头
        postMethod.setHeader("Content-Type","application/json");
        postMethod.setHeader("Authorization","Bearer"+ API_KEY);

        //设置请求体为 JSON 数据
        StringEntity entity = new StringEntity(payload.tostring(),"UTF-8");
        postMethod.setEntity(entity);
        // 执行请求
        HttpResponse response =client.execute(postMethod);
        int statusCode =response.getStatusLine().getStatusCode();
        if(statusCode != 200) {
            throw new RuntimeException("HTTP 请求失败，状态码:" + statusCode);
        }
        // 获取响应并解析
            String responseString = EntityUtils.toString(response.getEntity());
            JSONObject responseJson = JSONObject.parse0bject(responseString);
            JsONObject assistantMessage = responseJson.getJSONArray( "choices")
                    .getJSoNobject(0)
                    .getJSONObject("message");
        return assistantMessage;

    }*/
}